package cn.tedu.ivos.dictoption.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionParam;
import cn.tedu.ivos.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/dictOption")
public class DictOptionController {
    @Autowired
    DictOptionService dictOptionService;
    @GetMapping("select")
    public JsonResult selectDictOption(DictOptionQuery dictOptionQuery){
        log.debug("查询字典项,{}", dictOptionQuery);
        List<DictOptionVO> list = dictOptionService.selectDictOption(dictOptionQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveDictOption(DictOptionParam dictOptionParam){
        log.debug("保存字典项,{}", dictOptionParam);
        dictOptionService.saveDictOption(dictOptionParam);
        return JsonResult.ok();
    }

    @PostMapping("/delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id){
        log.debug("删除字典项,{}", id);
        dictOptionService.deleteDictOption(id);
        return JsonResult.ok();
    }

    @GetMapping("/select/{code}")
    public JsonResult selectDictOptionByCode(@PathVariable String code){
        log.debug("根据字典编码查询字典项,{}", code);
        List<DictOptionVO> list = dictOptionService.selectDictOptionByCode(code);
        return JsonResult.ok(list);
    }
}
